<template>
  <div class="search-cont">
    <img src="@/assets/lajichacha.png" alt class="cc-img">
    <div class="search">
      <input v-model="name" type="text" placeholder="这是什么垃圾">
      <span @click="routerLink(`search`)">
        <img src="@/assets/btn_search.png" alt class="search-btn">
      </span>
    </div>
  </div>
</template>

<script>
import { requestSearch } from '@/api/utils'
export default {
    data() {
        return {
            name: ''
        }
    },
    methods: {
        async routerLink(href) {
            const res = await requestSearch(this.name)
            this.$store.commit('utils/SAVE_SEARCH', res.data)
            this.$router.push({
                name: href,
                params: { data: res }
            })
        }
    }
}
</script>

<style lang="less" scoped>
.search-cont {
  display: flex;
  justify-content: space-between;
  align-items: center;
  white-space: nowrap;
  .search {
    position: relative;
    padding-left: 10px;
    border-radius: 20px;
    border: 2px solid #4076fb;
    box-sizing: border-box;
    span {
      width: 20px;
      height: 20px;
      position: absolute;
      top: 50%;
      right: 10px;
      transform: translateY(-50%);
    }
  }
}
.cc-img {
  width: 26%;
}
.search-btn {
  width: 100%;
}
input {
  height: 30px;
  line-height: 30px;
  border: none;
  font-size: 17px;
  outline: none;
  background: none;
}
</style>
